//
//  UIColor+Customer.m
//  MortgageHelper
//
//  Created by fly Mac on 16/7/11.
//  Copyright © 2016年 zhangxiang. All rights reserved.
//

#import "UIColor+Customer.h"

typedef unsigned int ADDColorType;

#define ADD_RED_MASK        0xFF0000
#define ADD_GREEN_MASK      0xFF00
#define ADD_BLUE_MASK       0xFF

#define ADD_RED_SHIFT       16
#define ADD_GREEN_SHIFT     8
#define ADD_BLUE_SHIFT      0

#define ADD_COLOR_SIZE      255.0

@implementation UIColor (Customer)

/**
 *  基础配色方案
 */
+ (UIColor*)add_colorWithRGBHexString:(NSString*)rgbStrValue
{
    ADDColorType rgbHexValue;
    
    NSScanner* scanner = [NSScanner scannerWithString:rgbStrValue];
    BOOL successful = [scanner scanHexInt:&rgbHexValue];
    
    if (!successful)
        return nil;
    
    return [self add_colorWithRGBHexValue:rgbHexValue];
}

+ (UIColor*)add_colorWithRGBHexValue:(ADDColorType)rgbValue
{
    return [UIColor colorWithRed:((CGFloat)((rgbValue & ADD_RED_MASK) >> ADD_RED_SHIFT))/ADD_COLOR_SIZE
                           green:((CGFloat)((rgbValue & ADD_GREEN_MASK) >> ADD_GREEN_SHIFT))/ADD_COLOR_SIZE
                            blue:((CGFloat)((rgbValue & ADD_BLUE_MASK) >> ADD_BLUE_SHIFT))/ADD_COLOR_SIZE
                           alpha:1.0];
}

+ (UIImage *)createImageWithColor:(UIColor *)color
{
    CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;
}




+ (UIColor *)themeColor
{
    return THEME_COLOR;
}

+ (UIColor *)noticeTextColor
{
    return [self add_colorWithRGBHexString:@"999999"];
}

+ (UIColor *)defaultTextColor
{
    return [self add_colorWithRGBHexString:@"666666"];
}

+ (UIColor *)titleColor
{
    return [self add_colorWithRGBHexString:@"333333"];
}

+ (UIColor *)yellowbgColor{
    return [UIColor yellowColor];
}



+ (UIColor *)grayBackgroundColor{
    return HexColor(0xb8b8b8);
}

+ (UIColor *)secondBackgroundColor
{
    return [self add_colorWithRGBHexString:@"f9f9f9"];
}
+ (void)setgradientlayerStartPoint:(CGPoint )startPoint startRGBHexString:(NSString *)startRGBHexString andEndPoint:(CGPoint )endPoint endRGBHexString:(NSString *)endRGBHexString inView:(UIView *)View{
    
    CAGradientLayer *gradientLayer=[CAGradientLayer layer];
    gradientLayer = [CAGradientLayer layer];
    
    gradientLayer.frame = View.bounds;
    [View.layer addSublayer:gradientLayer];
    //设置渐变颜色方向
    gradientLayer.startPoint = startPoint;
    gradientLayer.endPoint = endPoint;
    
    //设定颜色组
    gradientLayer.colors = @[(__bridge id)[self add_colorWithRGBHexString:startRGBHexString].CGColor,
                                  (__bridge id)[self add_colorWithRGBHexString:endRGBHexString].CGColor];
    
    //设定颜色分割点
    gradientLayer.locations = @[@(0.0f) ,@(0.4f)];

}
@end
